<?php
class Mwc_SystemPoint_Model_Userpoint extends Mage_Core_Model_Abstract{
    protected function _construct(){
        $this->_init('systempoint/userpoint');
    }

    public function getUserpointId(){
        return $this->getId();
    }

    public function getEmail(){
        return $this->_getData('email');
    }

    public function getGroupTitle(){
        return $this->_getData('group_title');
    }
    
    public function getShadowPoint(){
        return $this->_getData('shadow_point');
    }
//    
//    public function getOrderedPoint(){
//        return $this->_getData('ordered_point');
//    }
    
    public function getSharedPoint(){
        return $this->_getData('shared_point');
    }
    
    public function getUserPoint(){
        return $this->_getData('user_point');
    }
    
//    public function getAddDate(){
//        return $this->_getData('add_date');
//    }
//    
//    public function getExpDate(){
//        return $this->_getData('exp_date');
//    }
                                        
//    public function getOrderedPoint(){
//        /*
//        $resource = Mage::getSingleton('core/resource');
//        $query = $resource->getConnection('core_read');
//
//        $sql = "SELECT SUM(point) AS point " .
//            " from {$resource->getTableName('systempoint/log')} " .
//            " where email = '{$this->getEmail()} ";
//        var_dump($sql);die;
//        //$point = $query->fetchAll($sql);
//
//        return $point['point'];
//        */
//
//        $model = Mage::getModel('systempoint/log');
//        $collection = $model->getCollection();
//            //->addFieldToFilter('email', array('like' => "%{$this->getEmail()}"));
//            //->addFilter('email', "%{$this->getEmail()}", 'like');
//        //var_dump($collection->count());die;
//        $point = 0;
//        foreach($collection as $item){
//            if(stristr($item->getUserEmail(), $this->getEmail()) !== false){
//                $point += $item->getPoint();
//            }
//        }
//
//        return $point;
//    }

    
    public function loadByEmail($email){
    	//$model = Mage::getModel('systempoint/userpoint');
        $userpoint = $this->getCollection()->addFieldToFilter('email', $email);
        $arr[]='';
	    foreach($userpoint as $item){
            $arr['itemid'] = $item->getUserpointId();
            $arr['userpoint'] = $item->getUserPoint();
            $arr['shadowpoint'] = $item->getShadowPoint();
            $arr['orderedpoint'] = $item->getOrderedPoint();
            $arr['sharedpoint'] = $item->getSharedPoint();
            $arr['grouptitle'] = $item->getGroupTitle();
//            $arr['adddate'] = $item->getAddDate();
//            $arr['expdate'] = $item->getExpDate();
        }
        return $arr;
    }
}